package com.mk.cloud.common.domain;

import act.validation.NotBlank;
import org.beetl.sql.core.annotatoin.*;
import org.beetl.sql.core.mapper.BaseMapper;

import javax.persistence.Transient;
import java.util.List;

@Table(name = "cp_resource")
@TableTemplate("order by orderno")
@SuppressWarnings("unused")
public class CpResource {
    /**
     * 资源ID
     */
    @AssignID
    private String resourceid;
    /**
     * 子菜单
     */
    @Transient
    private List<CpResource> menus;
    /**
     * 此菜单总共有几级子菜单
     */
    @Transient
    private Integer level;
    @Transient
    private String id;
    @Transient
    private String name;
    @Transient
    private String view;
    @Transient
    private String icon;//资源图标

    /**
     * 角色是否拥有该资源
     * 0否，1是
     */
    @Transient
    private String isChecked;

    @Transient
    private String resourcepname;

    //排序号
    private Integer orderno;
    //资源PID
    private String resourcepid;
    //资源所属类型（0平台，1客户）
    private String rebelongtype;
    //简介
    private String remark;
    //图标
    private String resicon;
    //资源编码
    private String resourcecode;
    //资源名称
    private String resourcename;
    //状态 1-有效 0-无效
    private String resourcestate;
    //资源类型 显示的菜单 数据权限 0~1
    private String resourcetype;
    //资源地址
    private String resourceurl;

    public CpResource() {
    }

    public String getIcon() {
        return icon;
    }

    public void setIcon(String icon) {
        this.icon = icon;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getView() {
        return view;
    }

    public void setView(String view) {
        this.view = view;
    }

    public String getResourcepname() {
        return resourcepname;
    }

    public void setResourcepname(String resourcepname) {
        this.resourcepname = resourcepname;
    }

    public String getResourceid() {
        return resourceid;
    }

    public void setResourceid(String resourceid) {
        this.resourceid = resourceid;
    }

    public String getResourcepid() {
        return resourcepid;
    }

    public void setResourcepid(String resourcepid) {
        this.resourcepid = resourcepid;
    }

    public Integer getOrderno() {
        return orderno;
    }

    public void setOrderno(Integer orderno) {
        this.orderno = orderno;
    }


    public String getRebelongtype() {
        return rebelongtype;
    }

    public void setRebelongtype(String rebelongtype) {
        this.rebelongtype = rebelongtype;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    public String getResicon() {
        return resicon;
    }

    public void setResicon(String resicon) {
        this.resicon = resicon;
    }

    public String getResourcecode() {
        return resourcecode;
    }

    public void setResourcecode(String resourcecode) {
        this.resourcecode = resourcecode;
    }

    public String getResourcename() {
        return resourcename;
    }

    public void setResourcename(String resourcename) {
        this.resourcename = resourcename;
    }

    public String getResourcestate() {
        return resourcestate;
    }

    public void setResourcestate(String resourcestate) {
        this.resourcestate = resourcestate;
    }

    public String getResourcetype() {
        return resourcetype;
    }

    public void setResourcetype(String resourcetype) {
        this.resourcetype = resourcetype;
    }

    public String getResourceurl() {
        return resourceurl;
    }

    public void setResourceurl(String resourceurl) {
        this.resourceurl = resourceurl;
    }

    public List<CpResource> getMenus() {
        return menus;
    }

    public void setMenus(List<CpResource> menus) {
        this.menus = menus;
    }

    public Integer getLevel() {
        return level;
    }

    public void setLevel(Integer level) {
        this.level = level;
    }

    public String getIsChecked() {
        return isChecked;
    }

    public void setIsChecked(String isChecked) {
        this.isChecked = isChecked;
    }

    public interface Mapper extends BaseMapper<CpResource> {

        /**
         * 客户端
         * 查询客户端用户拥有的所有有效菜单资源
         * @param userid
         * @return
         */
        List<CpResource> frontGetResByUserid(@Param("userid") String userid);


        /**
         * 平台端
         * 查询平台端用户拥有的所有有效菜单资源
         * @param userid
         * @return
         */
        List<CpResource> backGetResByUserid(@Param("userid") String userid);

        /**
         * 客户端
         * 根据角色模板id查询相关资源
         * @param roleid
         * @return
         */
        List<CpResource> frontGetResByRoleid(@Param("roleid") String roleid);

        /**
         * 客户端
         * 实际角色拥有的资源
         * @param roleid
         * @return
         */
        List<CpResource> frontGetResByRoleidCustomer(@Param("roleid") String roleid);

        /**
         * 平台端
         * 根据角色id查询相关资源
         * @param roleid
         * @return
         */
        List<CpResource> backGetResByRoleid(@Param("roleid") String roleid);

        /**
         * 通用
         * 根据resourceid 删除资源菜单以及相关权限
         * @param resourceid
         * @return
         */
        int comDeleteResourceById(@Param("resourceid") String resourceid);

        /**
         * 通用
         * 保存资源排序和结构
         * @param res
         * @return
         */
        int comSaveResourceStructure(@Param("res") List<CpResource> res);


        /**
         * 通用
         * 查询当前编码是被那个资源占用
         * @param resourcecode
         * @param resourceid (忽略该资源)
         * @return
         */
        String comCheckResourceCode(@Param("resourcecode") String resourcecode, @Param("resourceid") String resourceid);

        CpResource getResourceByKey(@Param("resourceid") String resourceid);
        /**
         * 通用
         * 查询当前用户拥有的数据资源
         * @param userid
         * @return 数据资源的编码们
         */
        List<String> getPermissions(@Param("userid") String userid);
    }
}